package com.app.android.coliy.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.app.android.coliy.R;
import com.app.android.coliy.bean.PrintSettingInfo;
import com.app.android.coliy.event.Event_PrintSetting;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Administrator on 2018/6/20.
 */

public class PrintSettingActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_printsetting);
        initView();
    }

    LinearLayout ll_chufafangshi, ll_dayinyanshi, ll_dayinjingdu;
    RadioGroup rg_moshi, rg_chufafangshi, rg_dayinjingdu;
    TextView tv_dayinyanshi;
    SeekBar seekbar;

    PrintSettingInfo printSettingInfo = new PrintSettingInfo();

    //初始化控件
    private void initView() {
        setTitle(getString(R.string.printsetting_title));    //设置标题
        setLeftImgClickListener();  //设置左键返回
        setRightTextClickListener(getString(R.string.back_with_save));

        ll_chufafangshi = findViewById(R.id.ll_chufafangshi);
        ll_dayinyanshi = findViewById(R.id.ll_dayinyanshi);
        ll_dayinjingdu = findViewById(R.id.ll_dayinjingdu);
        rg_moshi = findViewById(R.id.rg_moshi);
        rg_chufafangshi = findViewById(R.id.rg_chufafangshi);
        rg_dayinjingdu = findViewById(R.id.rg_dayinjingdu);
        tv_dayinyanshi = findViewById(R.id.tv_dayinyanshi);
        seekbar = findViewById(R.id.seekbar);


        seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_dayinyanshi.setText(progress + "");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        //模式
        rg_moshi.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkId) {
                switch (checkId) {
                    case R.id.rb_moshi_1:
                        checkMoShi(0);
                        break;
                    case R.id.rb_moshi_2:
                        checkMoShi(1);
                        break;
                    case R.id.rb_moshi_3:
                        checkMoShi(2);
                        break;
                    default:
                        break;
                }
            }
        });
        rg_moshi.check(R.id.rb_moshi_1);

        //触发方式
        rg_chufafangshi.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkId) {
                switch (checkId) {
                    case R.id.rb_anjian:
                        check_chufafangshi(0);
                        break;
                    case R.id.rb_lianxu:
                        check_chufafangshi(1);
                        break;
                }
            }
        });
        rg_chufafangshi.check(R.id.rb_anjian);

        //打印精度
        rg_dayinjingdu.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkId) {
                switch (checkId) {
                    case R.id.rb_jingdu1200:
                        check_dayinjingdu(0);
                        break;
                    case R.id.rb_jingdu600:
                        check_dayinjingdu(1);
                        break;
                }
            }
        });
        rg_dayinjingdu.check(R.id.rb_jingdu1200);

    }

    private void checkMoShi(int index) {
        printSettingInfo.type = index;
        ll_chufafangshi.setVisibility(View.GONE);
        ll_dayinyanshi.setVisibility(View.GONE);
        ll_dayinjingdu.setVisibility(View.GONE);
        if (index == 0) {

        } else if (index == 1)    //标签模式 ：  打印延时
        {
            ll_dayinyanshi.setVisibility(View.VISIBLE);
        } else if (index == 2)       //自定义：触发方式  打印延时  打印精度
        {
            ll_chufafangshi.setVisibility(View.VISIBLE);
            ll_dayinyanshi.setVisibility(View.VISIBLE);
            ll_dayinjingdu.setVisibility(View.VISIBLE);
        }
    }

    //触发方式
    private void check_chufafangshi(int index) {
        printSettingInfo.trigger_mode = index;
    }

    //打印精度
    private void check_dayinjingdu(int index) {
        printSettingInfo.printing_precision = index;
    }

    //点击事件
    @Override
    public void onClick(View view) {
        super.onClick(view);
        Intent intent;
        switch (view.getId()) {
            case R.id.tv_right_text:
                printSettingInfo.message_delay = seekbar.getProgress();

                Event_PrintSetting eventPrintSetting = new Event_PrintSetting();
                eventPrintSetting.printSettingInfo = printSettingInfo;
                EventBus.getDefault().post(eventPrintSetting);
                finish();
                break;
        }
    }
}
